﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Constructor
{
    public partial class SettingsForm : Form
    {
        public SettingsForm()
        {
            InitializeComponent();

            switch(Properties.Settings.Default.defaultFrameType)
            {
                case CommonLib.FrameType.Exemplar:
                    defaultFrameType.Text = "Экземпляр";
                    break;
                case CommonLib.FrameType.Prototype:
                    defaultFrameType.Text = "Прототип";
                    break;
                case CommonLib.FrameType.Situation:
                    defaultFrameType.Text = "Ситуация";
                    break;
            }

            switch (Properties.Settings.Default.defaultInherit)
            {
                case CommonLib.TypeInherit.Overwrite:
                    this.defaultInherit.Text = "Overwrite";
                    break;
                case CommonLib.TypeInherit.Range:
                    this.defaultInherit.Text = "Range";
                    break;
                case CommonLib.TypeInherit.Same:
                    this.defaultInherit.Text = "Same";
                    break;
            }

            switch (Properties.Settings.Default.defaulSlotType)
            {
                case CommonLib.SlotType.AKO:
                    this.defaultSlotType.Text = "АКО";
                    break;
                case CommonLib.SlotType.Error:
                    this.defaultSlotType.Text = "Ошибка";
                    break;
                case CommonLib.SlotType.Next:
                    this.defaultSlotType.Text = "Следующий";
                    break;
                case CommonLib.SlotType.Production:
                    this.defaultSlotType.Text = "Продукция";
                    break;
                case CommonLib.SlotType.SubFrame:
                    this.defaultSlotType.Text = "Субфрейм";
                    break;
                case CommonLib.SlotType.Regular:
                    this.defaultSlotType.Text = "Обычный";
                    break;
            }
            accept_but.Enabled = false;
        }

        private void defaultFrameType_SelectedIndexChanged(object sender, EventArgs e)
        {
            accept_but.Enabled = true;
        }

        private void defaultSlotType_SelectedIndexChanged(object sender, EventArgs e)
        {
            accept_but.Enabled = true;
        }

        private void defaultInherit_SelectedIndexChanged(object sender, EventArgs e)
        {
            accept_but.Enabled = true;
        }

        private void accept_but_Click(object sender, EventArgs e)
        {
            switch (defaultSlotType.Text)
            {
                case "АКО":
                    Properties.Settings.Default.defaulSlotType = CommonLib.SlotType.AKO;
                    break;
                case "Ошибка":
                    Properties.Settings.Default.defaulSlotType = CommonLib.SlotType.Error;
                    break;
                case "Следующий":
                    Properties.Settings.Default.defaulSlotType = CommonLib.SlotType.Next;
                    break;
                case "Продукция":
                    Properties.Settings.Default.defaulSlotType = CommonLib.SlotType.Production;
                    break;
                case "Субфрейм":
                    Properties.Settings.Default.defaulSlotType = CommonLib.SlotType.SubFrame;
                    break;
                case "Обычный":
                    Properties.Settings.Default.defaulSlotType = CommonLib.SlotType.Regular;
                    break;
            }
            switch (defaultFrameType.Text)
            {
                case "Экземпляр":
                    Properties.Settings.Default.defaultFrameType = CommonLib.FrameType.Exemplar;
                    break;
                case "Прототип":
                    Properties.Settings.Default.defaultFrameType = CommonLib.FrameType.Prototype;
                    break;
                case "Ситуация":
                    Properties.Settings.Default.defaultFrameType = CommonLib.FrameType.Situation;
                    break;
            }
            switch (defaultInherit.Text)
            {
                case "Overwrite":
                    Properties.Settings.Default.defaultInherit = CommonLib.TypeInherit.Overwrite;
                    break;
                case "Range":
                    Properties.Settings.Default.defaultInherit = CommonLib.TypeInherit.Range;
                    break;
                case "Same":
                    Properties.Settings.Default.defaultInherit = CommonLib.TypeInherit.Same;
                    break;
            }
            Properties.Settings.Default.Save();
            accept_but.Enabled = false;
        }

        private void save_but_Click(object sender, EventArgs e)
        {
            accept_but_Click(null, EventArgs.Empty);
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }

        private void cancel_but_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();            
        }
    }
}
